/**
 * 权限相关的数据
 * Created by gcc on 2017/9/29.
 */

import Vue from "vue";
import  { Tooltip } from 'view-design'

// 页码相关
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 40,
  currentPage: 1
};

//页面状态相关
let status = {
  //查看图片
  modalImage: {
    isShow: false,
    url: ''
  },
  modalMessageSend:{
    isShow: false,
  },
  modalMessageAccount:{
    isShow: false,
  },
  modalMessageDetail:{
    isShow: false,
    message:{
      id :"",
      isAll: false,
      userId: "",
      pushPlatform: 0,
      messageAccount: "",
      type: 0,
      result: 0,
      createtime: "",
      content: "",
      user: {},

      title: "",
      isOpen: false,
      opentime: "",
    }
  },
  rules: {
    title: [
      {required: true, message: '标题不能为空', trigger: 'blur'}
    ],
    content: [
      {required: true, message: '正文不能为空', trigger: 'blur'}
    ],
  },
};

// 和网络交互相关的参数
let params = {
  //搜索条件
  searchParams:{
    userId:"",
    token:"",
    userName:"",
  },
  messageDetailParam:{
    messageId:""
  },
  messageAccountParam:{
    firstName:""
  },
  messageSendParam:{
    userId:"",
    userName:"",
    token:"",
    title:"",
    content:"",
  }
};

// 页面的数据源
let data = {
  messageList: [],
  accountList:[]
};

let tableTitles=function (self) {
  var titles =  [
 {
      type: 'index',
      title: '#',
      width: 60,
      key: 'index',
      align: 'center',
    },
    {
      title: '用户名',
      key: 'user',
      width: 120,
      align: 'center',
      render: (h, params) => {
        let username = Vue.prototype.$tiyHideUsername(params.row.user.name);
        return h('div', username);
      }
    },
    {
      title: '全局推送',
      key: 'isAll',
      width: 90,
      align: "center",
      render: (h, params) => {
        return (
          <div>
              {params.row.isAll ? "是" : "否"}
          </div>
        );

      }
    },
  {
      title: '标题',
      key: 'title',
      minWidth:300
    },
    //  {
    //   title: '推送平台',
    //   key: 'pushPlatform',
    //   width: 120,
    //   align: 'center',
    //   render: (h, params) => {
    //     return (
    //       <div>
    //         {self.getPlatform(params.row.pushPlatform)}
    //       </div>
    //     );
    //
    //   }
    // } ,
     {
      title: '消息类型',
      key: 'type',
      width: 120,
      align: 'center',
      render: (h, params) => {
        return (
          <div>
            {self.getType(params.row.type)}
          </div>
        );

      }
    } ,
    {
      title: '推送日期',
      width: 160,
      key: 'createtime',
      align: 'center',
      render: (h, params) => {
        return h('div', self.$tiyBJTime(params.row.createtime));
      }
    },
    {
      title: '状态',
      width: 60,
      key: 'isOpen',
      align: 'center',
      render: (h, params) => {
        var date = new Date(params.row.createtime);
        return h('div', params.row.isOpen ? "已读" : "未读");
      }
    },
    {
      title: '操作',
      key: 'action',
      width: 150,
      align: 'center',
      render: (h, params) => {
        return self.$authority(self.tRole.CHAT_1_201)?(<div>
            <i-button type="primary" size="small"  style="margin-right:5px"  onClick={() => {  self.showDetail(params.index);}}>查看</i-button>
            <i-button type="primary" size="small"   onClick={() => {  self.showEmail(params.index);}}>发送</i-button>
          </div>):(<div></div>);
      }
    }
  ]

  return self.$authTableTitles(titles);

  };

let tableAccountTitles=function (self) {
  var titles = [
    {
      type: 'index',
      title: '#',
      width: 60,
      key: 'index',
      align: 'center',
    },
    {
      title: '头像',
      key: 'avatar',
      width: 80,
      align: 'center',
      render: (h, params) => {

        return (
          <div>
            <img src={params.row.avatar} height={50} onClick={() => {
              status.modalImage.url = params.row.avatar;
              status.modalImage.isShow = true;
            }}></img>
          </div>
        );
      }
    },
    {
      title: '用户名',
      key: 'userName',
      align: 'center',
      minWidth: 150,
      render: (h, params) => {
        let username = Vue.prototype.$tiyHideUsername(params.row.userName);
        return h('div', username);
      }
    },
    {
      title: '消息开关',
      minWidth: 100,
      key: 'title',
      render: (h, params) => {
        return (
          <div>
            {params.row.isPushMessage === 1 ? "已打开" : "已关闭"}
          </div>
        );
      }
    },
    {
      title: '推送令牌',
      width: 100,
      render: (h, params) => {
        return (
          <div>
            {(params.row.messageAccount !== null &&  params.row.messageAccount !== "" ? "已生成" : "未生成")}
          </div>
        );
      }
    },
    {
      title: '操作',
      key: 'action',
      //fixed: 'right',
      width: 100,
      align: 'center',
      render: (h, params) => {
        return (params.row.isPushMessage === 1 && (params.row.messageAccount !== null &&  params.row.messageAccount !== "")) ?(
          <div>
            <i-button type="primary" size="small" onClick={() => {
              self.sendMessageShow(params.index);
            }}>发送消息
            </i-button>
          </div>):(<div></div>);
      }
    }
  ]

  return self.$authTableTitles(titles);

  };

export  default  {
  tPage: page,
  tStatus: status,
  tParams: params,
  tData: data,
  tableTitles:tableTitles,
  tableAccountTitles:tableAccountTitles,
};
